#include <iostream>
#include <algorithm>
#include <cstring>
#define MAXK 405
#define MAXC 40005
using namespace std;

struct box {
    int h, a, c;
};
box boxes[MAXK];
int K;
void solve();

bool cmp(box b1, box b2) {
    return b1.a < b2.a;
}
int dp[MAXC];
int main() {
    cin >> K;
    for (int i = 0; i < K; i++) {
        cin >> boxes[i].h >> boxes[i].a >> boxes[i].c;
    }
    solve();
    return 0;
}

void solve() {
    sort(boxes, boxes + K, cmp);
    memset(dp, -1, sizeof dp);
    dp[0] = 0;
    for (int i = 0; i < K; i++) {
        for (int j = 0; j <= boxes[i].a; j++) {
            if (dp[j] >= 0)
                dp[j] = boxes[i].c;
            else if (j - boxes[i].h >= 0 && dp[j - boxes[i].h] > 0)
                dp[j] = dp[j - boxes[i].h] - 1;
        }
    }
    for (int i = MAXC - 1; i >= 0; i--) {
        if (dp[i] != -1) {
            cout << i << endl;
            return;
        }
    }
}